package com.haoran.dwz.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.haoran.dwz.siteminder.interceptor.SiteminderInterceptor;


@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

     /**
      *	静态资源 
      */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/ws").setViewName("ws/websocket");
        registry.addViewController("/ws1").setViewName("ws/wechat");
        registry.addViewController("/ws2").setViewName("ws/websoket");
        registry.addViewController("/**/login").setViewName("login");
        registry.addViewController("/sys/menu").setViewName("sys/menu");
        registry.addViewController("/hello").setViewName("sys/hello");
        registry.addViewController("/**/install").setViewName("install");
        registry.addViewController("/error").setViewName("error");
        registry.addViewController("/403").setViewName("error/403");
        registry.addViewController("/401").setViewName("error/401");
        registry.addViewController("/404").setViewName("error/404");
    }
    
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**","/statics/**").addResourceLocations("classpath:/static/","classpath:/statics/");
        super.addResourceHandlers(registry);
    }
    
	@Value("${cors.pathPattern.acl:/kyeopenapi/**}")
	private String aclPathPattern;
    
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
		HandlerInterceptor interceptor = new SiteminderInterceptor();
		registry.addInterceptor(interceptor).addPathPatterns(aclPathPattern);
    	super.addInterceptors(registry);
    }
}
